#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>

/*Test isGameover. This function checks */
int main(){

  struct gameState state;
  int i;
  int j;
  int n;
  int gameEnd;
  int fail;
  int ret;
  srand(time(NULL));

  //No more than 12 provinces or if three supplycount are zero then game end.
  printf("Testing isGameover\n");
  for (n = 0; n < 2000; n++) {
    gameEnd = 0;
    j =0;
    //Choose a rand amount of province cards
    state.supplyCount[province] = rand()%12;

    if(state.supplyCount[province] == 0){
      printf("I was here\n");
      gameEnd = 1;
    }

    for (i = 0; i < 25; i++) {
      state.supplyCount[i] = rand() % 60;
      if(state.supplyCount[i] == 0){
        printf("I was there\n");
        j++;
      }
    }

    if(j >= 3){
      gameEnd = 1;
    }

    ret = isGameOver(&state);

    if(ret != gameEnd){
      printf("Test FAILED \n");
      printf("GameEnd: %d, Return: %d\n", gameEnd, ret);
      printf("Province Cards: %d\n", state.supplyCount[province]);
      for (i = 0; i < 25; i++) {
        printf("Supply Count of %d: %d\n",i ,state.supplyCount[i]);

      }
      fail++;
    }else{
      printf("I passed!\n");
    }

    //Reset test variables
    gameEnd = 0;
    j =0;
  }

  printf("isGameover Summary: %i tests failed. %f percent failure rate", fail, ((float)fail/2000));

}
